package com.pluszg.nutrition.model.order;

import com.pluszg.nutrition.common.bean.BaseModel;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;


/**
 * plus_order 订单表
 *
 * @author Plus
 * @version 1.0
 * @date 2020-04-29 21:05:39
 * @company pluszg
 */
@SuppressWarnings("serial")
@Setter
@Getter
public class Order extends BaseModel {

    /**
     * id
     */
    private String id;

    /**
     * 订单号
     */

    private String orderNo;

    /**
     * 账户编码
     */

    private String accountCode;

    /**
     * 商品编码
     */

    private String productCode;

    /**
     * 数量
     */

    private Integer count;

    /**
     * 金额
     */

    private BigDecimal amount;


    public String toString() {
        return new StringBuilder().append("Order{").
                append("id=").append(id).
                append(",orderNo=").append(orderNo).
                append(",accountCode=").append(accountCode).
                append(",productCode=").append(productCode).
                append(",count=").append(count).
                append(",amount=").append(amount).
                append('}').toString();
    }

    /**
     * 复制字段：
     * id, orderNo, accountCode, productCode,
     * count, amount
     */
    public Order copy() {
        Order order = new Order();
        order.id = this.id;
        order.orderNo = this.orderNo;
        order.accountCode = this.accountCode;
        order.productCode = this.productCode;
        order.count = this.count;
        order.amount = this.amount;
        return order;
    }

    /**
     * 比较字段：
     * id, orderNo, accountCode, productCode,
     * count, amount
     */
    public boolean test(Order t) {
        if (t == null) return false;
        return (this.id == null || this.id.equals(t.id))
                && (this.orderNo == null || this.orderNo.equals(t.orderNo))
                && (this.accountCode == null || this.accountCode.equals(t.accountCode))
                && (this.productCode == null || this.productCode.equals(t.productCode))
                && (this.count == null || this.count.equals(t.count))
                && (this.amount == null || this.amount.equals(t.amount))
                ;
    }

    public void update(Order element) {
        if (element == null)
            return;
        if (this.id != null && !this.id.isEmpty()) {
            element.id = this.id;
        }
        if (this.orderNo != null && !this.orderNo.isEmpty()) {
            element.orderNo = this.orderNo;
        }
        if (this.accountCode != null && !this.accountCode.isEmpty()) {
            element.accountCode = this.accountCode;
        }
        if (this.productCode != null && !this.productCode.isEmpty()) {
            element.productCode = this.productCode;
        }
        if (this.count != null) {
            element.count = this.count;
        }
        if (this.amount != null) {
            element.amount = this.amount;
        }
    }
}
